﻿using Autofac;
using BMS.IRepository;
using BMS.Repository;
using System.Reflection;

namespace BMS.Presentation.ServiceExtensions
{
    /// <summary>
    /// Autofac按模块配置
    /// </summary>
    public class AutofacIOC : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //注册工作单元
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>();

            //注册服务层
            builder.RegisterAssemblyTypes(Assembly.Load("BMS.Service"))
                .Where(m => m.Name.EndsWith("Service"))
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();

            //注册仓储层
            builder.RegisterAssemblyTypes(typeof(UserRepository).Assembly)
                .Where(m => m.Name.EndsWith("Repository"))
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();
        }
    }
}
